﻿using Microsoft.Office.OneNote;
using System.IO;
using System.Globalization;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace OneNoteFramework.Tests.Hierarchy
{
    [TestClass]
    public sealed class NotebookTests : HierarchyTestBase
    {
        [TestMethod]
        public void ChangeNotebookColor()
        {
            RunNotebookTest(notebook =>
            {
                notebook.Color = OneNoteColor.Cyan;
                
                notebook.SubmitChanges();
                notebook.Update();

                Assert.AreEqual(OneNoteColor.Cyan, notebook.Color);
            });
        }

        [TestMethod]
        public void CreatePage()
        {
            RunSectionTest(section =>
            {
                OneNotePage page = section.CreatePage();
                Assert.IsNotNull(page);
                Assert.AreEqual(page, section.Pages[0]);
                Assert.IsTrue(section.Delete(page));
            });
        }

        [TestMethod]
        public void CreatePageAndModifyContent()
        {
            RunPageTest(page =>
            {
                CultureInfo language = page.Language;
                Assert.IsNull(language);

                page.Language = CultureInfo.CurrentCulture;
                page.SubmitChanges();

                Assert.AreEqual(CultureInfo.CurrentCulture, page.Language);
            });
        }

        [TestMethod]
        public void CreateSectionAndGroup()
        {
            RunNotebookTest(notebook =>
            {
                const string groupName = "TestGroup";
                const string sectionName = "TestSection";

                OneNoteSectionGroup group = notebook.OpenSectionGroup(groupName);
                Assert.IsNotNull(group);
                Assert.AreEqual(groupName, group.Name);
                Assert.AreEqual(Path.Combine(notebook.Path, groupName), group.Path);
                Assert.AreEqual(0, group.Pages.Count);
                Assert.AreEqual(0, group.Sections.Count);

                OneNoteSection section = group.OpenSection(sectionName);
                Assert.IsNotNull(section);
                Assert.AreEqual(sectionName, section.Name);
                Assert.AreEqual(Path.Combine(group.Path, sectionName + ".one"), section.Path);
                Assert.AreEqual(0, section.Pages.Count);

                Assert.IsTrue(group.Delete(section));
                Assert.IsTrue(notebook.Delete(group));
            });
        }
    }
}
